package com.pay.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 支付宝机器人一些工具类
 * @author tianpeng
 *
 */
public class ZfbRobtoUtils {

	public static void main(String[] args) {
		String cookie = "JSESSIONID=RZ17lqh3gFbHnZarGJViGXLXfLTUgXauthRZ17GZ00; cna=GlYCFGDcRgcCAXFNkUWgBLdy; mobileSendTime=-1; credibleMobileSendTime=-1; ctuMobileSendTime=-1; riskMobileBankSendTime=-1; riskMobileAccoutSendTime=-1; riskMobileCreditSendTime=-1; riskCredibleMobileSendTime=-1; riskOriginalAccountMobileSendTime=-1; ctoken=U5nwwEFKDTZqYw5y; LoginForm=alipay_login_auth; alipay=\"K1iSL16QY1TOa0TWpNJUKpg336kutio3Se7lnfOBbQ==\"; CLUB_ALIPAY_COM=2088722153529552; iw.userid=\"K1iSL16QY1TOa0TWpNJUKg==\"; ali_apache_tracktmp=\"uid=2088722153529552\"; session.cookieNameId=ALIPAYJSESSIONID; ALIPAYJSESSIONID=RZ17lqh3gFbHnZarGJViGXLXfLTUgXauthRZ17GZ00; zone=GZ00C; JSESSIONID=1949693435351E170882602780FFB39B; spanner=6PukVKHDlHFpraYdVqmOIOA3soyi4YDy4EJoL7C0n0A=; rtk=kT1/bUNwd9H4k0XgYTqBnvvVC2aRoJjNGQPtgINB2FXzoJhygM7; UM_distinctid=1677ecb9e8f160-0b97e4b976064a-35677607-13c680-1677ecb9e90b27; CNZZDATA1253107971=1269155715-1544016549-https%253A%252F%252Fb.alipay.com%252F%7C1544016549" ;
		String userId = getUserId(cookie);
		String ctoken = getCToken(cookie);
		System.out.println(userId);
		System.out.println(ctoken);
	}
	
	/**
	 * 根据cookie来取得userId
	 * @param cookie
	 * @return
	 */
	public static String getUserId(String cookie) {
		Pattern pattern = Pattern.compile("CLUB_ALIPAY_COM=(.+?);") ;
		Matcher matcher = pattern.matcher(cookie);
		if(matcher.find()) {
			//如果有
			String userId = matcher.group(1);
			return userId ;
		}
		return "" ;
	}
	
	/**
	 * 根据cookie来取得ctoken
	 * @param cookie
	 * @return
	 */
	public static String getCToken(String cookie) {
		Pattern pattern = Pattern.compile("ctoken=(.+?);") ;
		Matcher matcher = pattern.matcher(cookie);
		if(matcher.find()) {
			//如果有
			String ctoken = matcher.group(1);
			return ctoken ;
		}
		return "" ;
	}
}
